package com.psp.web.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.web.controller.res.*;
import com.psp.web.controller.res.bean.*;
import com.psp.web.controller.springmvc.req.*;

/**
 * 商品-相关接口
 **/
@Controller
@RequestMapping(value = "/psp/bs", produces = "application/json")
public class SBusinessController {
	@Autowired
	com.psp.web.controller.BusinessController businessController;

	/**
	 * 服务类型
	 **/
	@RequestMapping("/v1/getTypes")
	@ResponseBody
	public ObjectResult<RServicesTypeBean> getTypes(@Validated GetServiceTypeParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RServicesTypeBean> res = new ObjectResult<RServicesTypeBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getTypes(param, request, response);
	}

	/**
	 * 服务菜单
	 **/
	@RequestMapping("/v1/getMenus")
	@ResponseBody
	public ObjectResult<RServicesMenusBean> getMenus(@Validated GetServiceMenusParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RServicesMenusBean> res = new ObjectResult<RServicesMenusBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getMenus(param, request, response);
	}

	/**
	 * 商品列表
	 **/
	@RequestMapping("/v1/getLists")
	@ResponseBody
	public ListResult<RProductListBean> getLists(@Validated GetProductListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProductListBean> res = new ListResult<RProductListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getLists(param, request, response);
	}

	/**
	 * 服务详情
	 **/
	@RequestMapping("/v1/getDetail")
	@ResponseBody
	public ObjectResult<RBusinessDetailBean> getDetail(@Validated GetBusinessDetailParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RBusinessDetailBean> res = new ObjectResult<RBusinessDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getDetail(param, request, response);
	}

	/**
	 * 服务属性
	 **/
	@RequestMapping("/v1/getProductAttributes")
	@ResponseBody
	public ListResult<RAttributeBean> getProductAttributes(@Validated GetProductAttributesParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RAttributeBean> res = new ListResult<RAttributeBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getProductAttributes(param, request, response);
	}

	/**
	 * 服务信息
	 **/
	@RequestMapping("/v1/getProductInfoBySkuno")
	@ResponseBody
	public ObjectResult<RProductSkuBean> getProductInfoBySkuno(@Validated GetProductInfoBySkunoParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProductSkuBean> res = new ObjectResult<RProductSkuBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getProductInfoBySkuno(param, request, response);
	}

	/**
	 * 服务评价
	 **/
	@RequestMapping("/v1/getComments")
	@ResponseBody
	public ListResult<RBusinessCommentsBean> getComments(@Validated GetBusinessCommentsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RBusinessCommentsBean> res = new ListResult<RBusinessCommentsBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getComments(param, request, response);
	}

	/**
	 * 相关服务
	 **/
	@RequestMapping("/v1/getSimilarProduct")
	@ResponseBody
	public ObjectResult<RSimilarProductBean> getSimilarProduct(@Validated GetSimilarProductParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RSimilarProductBean> res = new ObjectResult<RSimilarProductBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return businessController.getSimilarProduct(param, request, response);
	}
}
